﻿using ChronoScript_Compiler.Language;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Viper;
using Viper.Opcodes;

namespace ChronoScript_Compiler.CodeGen
{
    public partial class CodeGen
    {
        public static Assembly Assembler;
        public SymbolTable Symbols;
        public StringBuilder Output = new StringBuilder("");
        public List<LanguageDefinition.SyntaxNode> AST;
        public List<string> Errors = new List<string>();
        public string ReturnType = "";
        public CodeGen()
        {
            this.Symbols = new SymbolTable();
        }
        public void BeginGeneration(List<LanguageDefinition.SyntaxNode> tree)
        {
            Assembler.Emit(new bra("main"));
            AST = tree;
            foreach (LanguageDefinition.SyntaxNode sn in AST)
            {
                if (sn is LanguageDefinition.Method)
                {
                    CreateMethod(sn as LanguageDefinition.Method);
                }
            }
            if (this.Errors.Count > 0)
                Console.WriteLine(this.Errors.Count.ToString() + " error(s) found during compiling!");
        }
    }
}
